package StudyCode.summary.symboliclink;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ReadsAttributesTargetFileToLink {
	public static void main(String[] args) {
		Path link = FileSystems.getDefault().getPath("test");
		Path target = FileSystems.getDefault().getPath("E:/Copy", "test.txt");

		try {
			PosixFileAttributes attrs = Files.readAttributes(target,
					PosixFileAttributes.class);
			FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions
					.asFileAttribute(attrs.permissions());

			Files.createSymbolicLink(link, target, attr);
		} catch (IOException | UnsupportedOperationException | SecurityException e) {
			System.err.println(e);
		}

	}
}
